#ifndef TABLEVIEWMODEL_H
#define TABLEVIEWMODEL_H

#include <QAbstractTableModel>

struct Data
{
    bool bChecked; //是否选中
    QString name;
    bool bSwitch;
};

class TableViewModel : public QAbstractTableModel
{
    Q_OBJECT
    enum TableColumn
    {
        CL_checked = 0,
        CL_name,
        CL_switch,
        CL_oper
    };

public:
    TableViewModel(QObject *parent);
    ~TableViewModel();
    void updateData(QList<Data> recordList);
    void setHorizontalHeader(const QStringList& headers);

    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    int columnCount(const QModelIndex &parent = QModelIndex()) const;

    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    void onStateChanged();

public slots:
    void onStateChanged(int state);

signals:
    void stateChanged(int state);

private:
    QStringList m_HorizontalHeader;
    QList<Data> m_recordList;
};

#endif // TABLEVIEWMODEL_H
